package com.my.toolkit.mock;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.LazyLoader;

public class MockUtil{

	public static <T> T mock(Class<T> clazz,MockCallback callback){
		Enhancer e=new Enhancer();
		e.setSuperclass(clazz);
		e.setCallback(callback);
		return (T)e.create();
	}

	public static <T> T lazy(Class<T> clazz,LazyLoader loader){
		try{
			//TODO cglib获取对象时在方法上用了synchronized,可以考虑优化下
			return (T)Enhancer.create(clazz,loader);
		}catch(Exception ex){
			throw new RuntimeException(ex.getMessage(),ex);
		}
	}
	
	
}
